import {View, ScrollView} from "@tarojs/components";
import Utils from "@/utils/common";
import {Cell, Empty} from "@antmjs/vantui";
import RouthPath from "@/common/RouthPath";
import {useEffect, useState} from "react";
import {machineList2Api} from "@/common/apis/home_datasource";
import {MachineModel} from "@/common/apis/model";
import LocalData from "@/common/local_data";


definePageConfig({
  navigationBarTitleText: '选择机器'
})

export default function MachineList() {
  const [machines, setMachines] = useState<MachineModel[]>()

  useEffect(() => {
    machineList2Api().then((res) => {
      setMachines(res)
    })
  }, []);
  return (
    <View
      style={{
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        justifyContent: 'center',
        width: '100%',
        height: '100VH',
        boxSizing: 'border-box',
        padding: '10px',
      }}
    >
      <ScrollView scrollY style={{height: '100%'}}>
        {
          machines ? machines.map((machine, index) => (<Cell key={index} title={machine.name} isLink onClick={() => {
            Utils.navigateTo({
              url: Utils.getUrlWithObject(machine.type === LocalData.notTimeId ? RouthPath.machineOrderList : RouthPath.orderStatisticsPage, machine)
            })
          }}
          />)) : <Empty description='暂无数据'/>
        }
      </ScrollView>
    </View>
  )

}


